﻿package command {
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class BoldCommand implements ICommand {
		private var inputField:TextField;
		private var index:int;
		private var text:String;
		private var tf:TextFormat;
		
		public function BoldCommand(inputField:TextField, index:int, text:String, tf:TextFormat = null):void {
			this.inputField = inputField;
			this.index = index;
			this.text = text;
			this.tf = tf;
		}
		
		public function redo():void {
			inputField.replaceText(index, index, text);
			if(tf != null) {
				inputField.setTextFormat(tf, index, index + text.length);
			}
		}
		public function undo():void {
			inputField.replaceText(index, index + text.length, "");
		}
	}
}